// var setSession = require('./common/session').setSession;
// var checkSession = require('./common/session').checkSession;
// var index = require('./routes/index').index;
// var adminLogin = require('./routes/admin/login').login;
// var adminCheckLogin = require('./routes/admin/login').checkLogin;
// var adminIndex = require('./routes/admin/index').index;
// var adminLoginSuccess = require('./routes/admin/login').loginSuccess;
// var newsList = require('./routes/admin/newsList').newsList;
// var add = require('./routes/admin/addnews').add;
// var addNews = require('./routes/admin/addnews').addNews;
// var getQiniuToken = require('./common/getQiniuToken').getQiniuToken;
// var deleteNews = require('./routes/admin/deleteNews').deleteNews;
// var article = require('./routes/article').article;
// var demo1 = require('./routes/demo1').demo1;
// exports.router = function(app){
//   app.get('/',index);
//   app.get('/demo1',demo1);
//   app.get('/news/:news_id.html',article)
//   app.get('/admin/login',adminLogin);
//   app.post('/admin/login',adminCheckLogin, setSession, adminLoginSuccess);
//   app.get('/admin', adminIndex);
//   //新闻列表页
//   app.get('/admin/newsList',[checkSession,newsList]);
//   //后台添加新闻页面
//   app.get('/admin/addNews',[add]);
//   //获取七牛token
//   app.post('/uptoken',getQiniuToken);
//   //后台添加新闻页面接口
//   app.post('/addNews',[checkSession,addNews]);
//   //删除新闻接口
//   app.post('/deleteNews',[checkSession,deleteNews]);
// }
var setSession = require('./common/session').setSession;
var checkSession = require('./common/session').checkSession;
var cmsLogin = require('./routes/admin/login');
var cmsAdmin = require('./routes/admin/index');
var cmsNewsList = require('./routes/admin/newsList').newsList;
var cmsAdd = require('./routes/admin/addnews');
var index = require('./routes/index').index;
var getQiniuToken = require('./common/getQiniuToken').getQiniuToken;
var cmsDelete = require('./routes/admin/deleteNews').deleteNews;
var article = require('./routes/article').article;
var indexGetPage = require('./routes/page').page;
var cheerio = require("cheerio");
var curlServer = require("./common/curl");
 
var url = "https://mp.weixin.qq.com/s?__biz=MzUzODk1MjM5MQ==&mid=2247484743&idx=1&sn=b03c64c5d6d31ee7312580a5d9c83578&chksm=face92efcdb91bf95f3bf57b10f043604e3ed4004ef0507cc10f8b1e824dbed3440b4c937ab2&scene=38#wechat_redirect"

curlServer.download(url, function(data) {
  if (data) {
    //console.log(data);
 
    var $ = cheerio.load(data);
    $('#js_content img').each(function(i,e){
      if($(e).attr('data-type') == 'png' || $(e).attr('data-type') == 'jpeg' || $(e).attr('data-type') == 'jpg'){
        console.log($(e).attr('data-src'));
      }
    })
 
    console.log("done");
  } else {
      console.log("error");
  } 
});
exports.router = function(app){
  app.get('/',index)
  //获取七牛token
  app.post('/uptoken',getQiniuToken);
  //删除新闻接口
  app.post('/deleteNews',[cmsDelete]);
  //cms登录接口
  app.get('/admin/login',[cmsLogin.login]);
  app.post('/admin/login',[cmsLogin.checkUser, setSession, cmsLogin.loginSuccess]);
  app.get('/admin/',[checkSession,cmsAdmin.index]);
  app.get('/admin/newsList',[checkSession,cmsNewsList]);
  app.get('/admin/addNews',[checkSession,cmsAdd.add]);
  app.post('/addNews',cmsAdd.addNews);
  app.get('/article/(:id).html',article);
  app.post('/indexGetPage',indexGetPage);
}